package cn.stylefeng.guns.modular.manager.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowConfig;
import cn.stylefeng.guns.modular.manager.model.params.FlowConfigParam;
import cn.stylefeng.guns.modular.manager.service.FlowConfigService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;


/**
 * 配置控制器
 *
 * @author yumker
 * @Date 2021-01-07 17:22:24
 */
@Controller
@RequestMapping("/flowConfig")
public class FlowConfigController extends BaseController {

    private String PREFIX = "/manager/flowConfig";

    @Autowired
    private FlowConfigService flowConfigService;

    /**
     * 跳转到主页面
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/flowConfig.html";
    }

    /**
     * 编辑接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(FlowConfigParam flowConfigParam) {
        if(!StringUtils.isEmpty(flowConfigParam.getAgreementDetail())){
            try {
                flowConfigParam.setAgreementDetail(URLDecoder.decode(flowConfigParam.getAgreementDetail(),"UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        this.flowConfigService.update(flowConfigParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author yumker
     * @Date 2021-01-07
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail() {
        FlowConfigParam flowConfigParam = new FlowConfigParam();
        flowConfigParam.setConfigId(1L);
        FlowConfig detail = this.flowConfigService.getById(flowConfigParam.getConfigId());
        return ResponseData.success(detail);
    }
}


